package com.google.gsaguide.DAO;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * This Class is the connection with SQLite.
 * @author Jordan Lira
 */
public class SQLConnection extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "gsa.db";
    public static final String TABLE_AMBASSADORS = "ambassador";
    public static final int DATABASE_VERSION = 3;

    public static final String COLUMN_ID = "id";
    public static final String COLUMN_NAME = "name";
    public static final String COLUMN_IMAGE_URL = "image";
    public static final String COLUMN_UNIVERSITY = "university";
    public static final String COLUMN_LOCATION = "location";
    public static final String COLUMN_PROFILE_URL = "profileURL";

    private final String SQL_CREATE_ENTRIES =
            "CREATE TABLE " + TABLE_AMBASSADORS +
                    "( " +
                    COLUMN_ID + " TEXT," +
                    COLUMN_NAME + " TEXT," +
                    COLUMN_UNIVERSITY + " TEXT," +
                    COLUMN_LOCATION + " TEXT," +
                    COLUMN_PROFILE_URL + " TEXT," +
                    COLUMN_IMAGE_URL + " TEXT" +
                    "); ";

    public SQLConnection(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES);
    }

    /**
     * Delete the table and add another overwriting it
     */
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
        sqLiteDatabase.execSQL("DROP TABLE ambassador");
        onCreate(sqLiteDatabase);

    }
}
